package com.movitech.mobile.ddzy.modules.jobs;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.movitech.mobile.cz.base.purchase.entity.WFlowFormAwardBid;
import com.movitech.mobile.cz.base.purchase.service.WFlowFormAwardBidService;
import com.movitech.mobile.ddzy.modules.bpm.bizservice.BaseDataSynService;
import com.movitech.mobile.task.CalibrationBidSynRabbitMQProducer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;

/**
 * 定标流程审批通过后同步成本系统定时任务
 *
 * @author luodz
 * @version 1.0.0
 * @description 定标流程审批通过后同步成本系统定时任务
 * @createTime 2023/04/10
 */
@Component
public class SynCalibrationBidJob {

    @Autowired
    private WFlowFormAwardBidService wFlowFormAwardBidService;
    @Autowired
    private CalibrationBidSynRabbitMQProducer calibrationBidSynRabbitMQProducer;

    @Scheduled(cron = "${job.scheduled.awardbid2cost}")
    public void synAwardBid2Cost() {
        System.out.println("=============定标流程审批通过后同步成本系统定时任务 START===============");
        // 查询未同步的定标信息
        List<Map<String, Object>> lst = wFlowFormAwardBidService.getSupplierAwardBidsUnSyn();
        if(lst!=null && lst.size()>0){
            calibrationBidSynRabbitMQProducer.producer(JSONArray.toJSONString(lst));
            for(Map<String,Object> map : lst){
                // 更新定标信息为已同步。
                String id = map.get("scalingUuid").toString();
                wFlowFormAwardBidService.updateSynStatus(id);
            }
        }
        System.out.println("=============定标流程审批通过后同步成本系统定时任务 END===============");
    }
}
